package wangjg.test.socks;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Socks5Server {
	private ServerSocket ss;

	public Socks5Server() {
		try {
			ss = new ServerSocket(1080);
			while (true) {
				Socket socket = ss.accept();
				
				handle(socket);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private void handle(final Socket socket){
		Socks5ClientHandler d=new Socks5ClientHandler(socket);
		Thread readThread = new Thread(d);
		readThread.start();
	}
	
	private void receiv(final InputStream is){
		Thread readThread = new Thread(){
			public void run(){
				try {
					byte[] buffer = new byte[100];
					int len=0;
					while((len=is.read(buffer))!=-1){
						System.out.println("  "+SocksUtil.toHex(buffer,len));
						System.out.println("  "+new String(buffer,0,len));
						System.out.println();
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		};
		readThread.start();
	}
	
	
	public static void main(String[] args) {
		new Socks5Server();
	}
}